package com.parking.mgr.common.pojo.response;

import com.parking.mgr.common.enums.LoginStatusEnums;
import com.parking.mgr.common.enums.NeedLoginStatusEnums;
import com.parking.mgr.common.pojo.login.LoginStatus;
import com.parking.mgr.common.pojo.page.PageResult;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Result
 * @Description TODO
 * @author: zhijianpu
 * @Date: 2025/2/28
 */
@Data
@ApiModel(description = "返回响应数据")
public class Result<T> {

    public static final String DEFAULT_MESSAGE = "操作成功";

    public static final String I18N_DEFAULT_MESSAGE = "i18n_message_operation_success";

    public static final String DEFAULT_ERROR_MESSAGE = "网络异常";

    public static final Integer DEFAULT_SUCCESS_CODE = 200;

    public static final Integer DEFAULT_ERROR_CODE = 500;

    /**
     * 请求是否成功
     */
    @ApiModelProperty(value = "请求是否成功")
    private Boolean success;

    /**
     * 响应状态码
     */
    @ApiModelProperty(value = "响应状态码")
    private Integer code;

    /**
     * 响应信息
     */
    @ApiModelProperty(value = "响应信息")
    private String message;

    /**
     * 响应对象
     */
    @ApiModelProperty(value = "响应对象")
    private T data;


    /**
     * 下一个请求地址
     */
    @ApiModelProperty(value = "下一个请求地址")
    private String nextUrl;

    /**
     * 分页结果
     */
    @ApiModelProperty(value = "分页结果")
    private PageResult pagination;

    /**
     * 登录状态集
     */
    @ApiModelProperty(value = "登录状态集")
    private LoginStatus loginStatus;

    /**
     * 响应成功数据集
     */
    @ApiModelProperty(value = "响应成功数据集")
    private Successes successes;

    @ApiModelProperty(value = "响应成功数据集")
    private List<String> successeList;

    /**
     * 响应失败消息体
     */
    @ApiModelProperty(value = "响应失败消息体")
    private List<Failures> failures;

    public Result() {
    }

    /**
     * 操作成功 -> 包含响应状态码、响应消息、响应成功数据集
     *
     * @param success
     * @param code
     * @param message
     */
    public Result(Boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;

        Successes successe = new Successes(code, message);
        this.successes = successe;
        List<Successes> successes = new ArrayList<>();

        successes.add(successe);
    }

    /**
     * 返回体 -> 包含响应状态码、响应消息、响应对象、响应成功数据集
     *
     * @param success
     * @param code
     * @param message
     * @param data
     */
    public Result(Boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;

        Successes successe = new Successes(code, message);
        this.successes = successe;
        List<Successes> successes = new ArrayList<>();

        successes.add(successe);
    }

    /**
     * 返回体 -> 包含响应状态码、响应消息、响应对象、分页对象、响应成功数据集
     *
     * @param success
     * @param code
     * @param message
     * @param data
     * @param pagination
     */
    public Result(Boolean success, Integer code, String message, T data,
                  PageResult pagination) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
        this.pagination = pagination;

        Successes successe = new Successes(code, message);
        this.successes = successe;
        List<Successes> successes = new ArrayList<>();

        successes.add(successe);
    }

    /**
     * 返回体 -> 包含响应状态码，响应对象，响应失败消息体
     *
     * @param success
     * @param code
     * @param data
     * @param failuresResult
     */
    public Result(Boolean success, Integer code, String message, T data, List<Failures> failuresResult) {
        this.success = success;
        this.code = code;
        this.data = data;
        this.message = message;
        this.failures = failuresResult;
    }


    /**
     * 返回体 -> 包含所有属性
     *
     * @param success
     * @param code
     * @param message
     * @param data
     * @param pagination
     * @param loginStatus
     * @param failuresResult
     */
    public Result(Boolean success, Integer code, String message, T data,
                  PageResult pagination, LoginStatus loginStatus, List<String> successeList,
                  List<Failures> failuresResult) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
        this.pagination = pagination;
        this.loginStatus = loginStatus;
        this.failures = failuresResult;
        this.successeList = successeList;

    }

    public Result(Boolean success, Integer code, String message, T data,
                  PageResult pagination, LoginStatus loginStatus,
                  List<String> messageList) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
        this.pagination = pagination;
        this.loginStatus = loginStatus;
        this.successeList = messageList;
    }


    public static <T> Result<T> success() {
        return new Result<>(true, DEFAULT_SUCCESS_CODE,  DEFAULT_MESSAGE, null, null, new LoginStatus(LoginStatusEnums.LOGIN_STATE.getCode(), NeedLoginStatusEnums.NEED_LOGIN.getCode()), null, null);
    }

    public static <T> Result<T> successMessageList(List<String> messageList) {
        return new Result<>(true, DEFAULT_SUCCESS_CODE,  DEFAULT_MESSAGE, null, null, new LoginStatus(LoginStatusEnums.LOGIN_STATE.getCode(), NeedLoginStatusEnums.NEED_LOGIN.getCode()), messageList);
    }

    public static <T> Result<T> successMessage(String message) {
        return new Result<>(true, DEFAULT_SUCCESS_CODE,  DEFAULT_MESSAGE, null, null, new LoginStatus(LoginStatusEnums.LOGIN_STATE.getCode(), NeedLoginStatusEnums.NEED_LOGIN.getCode()), null, null);
    }

    public static <T> Result<T> successMessageWith500Code(String message, List<Failures> failures) {
        return new Result<>(true, DEFAULT_SUCCESS_CODE,  message, null, null, new LoginStatus(LoginStatusEnums.LOGIN_STATE.getCode(), NeedLoginStatusEnums.NEED_LOGIN.getCode()), null, failures);
    }

    public static <T> Result<T> successMessage(String message, T data) {
        return new Result<>(true, DEFAULT_SUCCESS_CODE,  message, data, null, new LoginStatus(LoginStatusEnums.LOGIN_STATE.getCode(), NeedLoginStatusEnums.NEED_LOGIN.getCode()), null, null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(true, DEFAULT_SUCCESS_CODE, DEFAULT_MESSAGE, data, null, new LoginStatus(LoginStatusEnums.LOGIN_STATE.getCode(), NeedLoginStatusEnums.NEED_LOGIN.getCode()), null, null);
    }

    public static <T> Result<T> success(T data, LoginStatus loginStatus) {
        return new Result<>(true, DEFAULT_SUCCESS_CODE, DEFAULT_MESSAGE, data, null, loginStatus, null, null);
    }

    public static <T> Result<T> success(T data, PageResult pageResult) {
        return new Result<>(true, DEFAULT_SUCCESS_CODE,  DEFAULT_MESSAGE, data, pageResult, new LoginStatus(LoginStatusEnums.LOGIN_STATE.getCode(), NeedLoginStatusEnums.NEED_LOGIN.getCode()), null, null);
    }

    public static <T> Result<T> success(String message, T data, LoginStatus loginStatus) {
        return new Result<T>(true, DEFAULT_SUCCESS_CODE, message, data, null, loginStatus, null, null);
    }

    public static <T> Result<T> success(String message, T data, PageResult pagination, LoginStatus loginStatus) {
        return new Result<T>(true, DEFAULT_SUCCESS_CODE, message, data, pagination, loginStatus, null, null);
    }

//    public static <T> Result<T> success(T data, LoginStatus loginStatus) {
//        return new Result<T>(true, DEFAULT_SUCCESS_CODE,  MessageUtils.message(I18N_DEFAULT_MESSAGE, DEFAULT_MESSAGE), data,null, loginStatus, null);
//    }

    public static <T> Result<T> success(T data, PageResult pagination, LoginStatus loginStatus) {
        return new Result<T>(true, DEFAULT_SUCCESS_CODE,  DEFAULT_MESSAGE, data, pagination, loginStatus, null, null);
    }

    public static <T> Result<T> success(Integer code, String message, T data, PageResult pagination, LoginStatus loginStatus) {
        return new Result<T>(true, code, DEFAULT_MESSAGE, data, pagination, loginStatus, null, null);
    }

//    public static <T> Result<T> error(String message, LoginStatus loginStatus, List<Failures> failures) {
//        return new Result<>(false, DEFAULT_ERROR_CODE, MessageUtils.message(I18N_DEFAULT_MESSAGE, DEFAULT_MESSAGE), null, null, loginStatus, null, failures);
//    }

    public static <T> Result<T> error(Integer code, String message, LoginStatus loginStatus, List<Failures> failures) {
        return new Result<>(false, code, DEFAULT_MESSAGE, null, null, loginStatus, null, failures);
    }

    public static <T> Result<T> error(T data, LoginStatus loginStatus, List<Failures> failures) {
        return new Result<>(false, DEFAULT_SUCCESS_CODE, DEFAULT_MESSAGE, data, null, loginStatus, null, failures);
    }

    public static <T> Result<T> error(Integer code, T data, LoginStatus loginStatus, List<Failures> failures) {
        return new Result<T>(false, DEFAULT_SUCCESS_CODE, DEFAULT_MESSAGE, data, null, loginStatus, null, failures);
    }

    public static <T> Result<T> error(Integer code, T data, List<Failures> failures) {
        return new Result<T>(false, DEFAULT_SUCCESS_CODE, DEFAULT_MESSAGE, data, failures);
    }


}
